package checkers_seperate_classes;

import javax.swing.table.DefaultTableModel;

public class MyDefaultTableModel extends DefaultTableModel {

	private static final long serialVersionUID = 1L;
	
	public String toString() {
		StringBuffer sb = new StringBuffer();
		final String columnSeperation = "  ";
		sb.append(String.format("%5s", " "));
		for (int iCol=0; iCol<this.getColumnCount(); iCol++) {
			sb.append(columnSeperation+getColumnName(iCol));
		}
		for (int iRow=0; iRow<this.getRowCount(); iRow++) {
			sb.append('\n');
			sb.append(String.format("%5d", iRow+1));
			for (int iCol=0; iCol<this.getColumnCount(); iCol++) {
				final String colName = getColumnName(iCol);
				final int currentLength = colName.length();
				final String fmt = String.format("%%%ds", currentLength);
				final String str = String.format(fmt, colName);
				sb.append(columnSeperation+str);
			}
		}
		return sb.toString();
	}

}
